package com.woniu.carrent.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.woniu.carrent.mapper.TUserinfoMapper;
import com.woniu.carrent.pojo.TUser;
import com.woniu.carrent.pojo.TUserinfo;
import com.woniu.carrent.pojo.dto.TUserDto;
import com.woniu.carrent.service.TUserService;
import com.woniu.carrent.util.ResultMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SaCheckLogin
@RestController
@RequestMapping("/tuser")
@CrossOrigin
public class TUserController {
    @Autowired
    private TUserService TUserService;
    @Autowired
    private TUserinfoMapper tUserinfoMapper;
    /**
     * 查询用户的信息
     * @param tuserDto
     */
    @RequestMapping("/selectUser")
    public ResultMessage selectUser(@RequestBody TUserDto tuserDto) {
        TUser tuser = new TUser();
        BeanUtils.copyProperties(tuserDto, tuser);
        Integer userid = tuser.getUserid();
        TUser TUser = TUserService.selectInfoByUserId(userid);
        return new ResultMessage("查询成功", TUser,200);
    }
    /**
     * 修改用户信息
     * @param TUserinfo
     */
    @RequestMapping("/updateUser")
    public ResultMessage updateUser(@RequestBody TUserinfo TUserinfo) {
        int flag = tUserinfoMapper.updateById(TUserinfo);
        if (flag > 0) {
            return  ResultMessage.success("修改成功");
        }
        return ResultMessage.fail("修改失败");
    }
}
